<?php
	require "../banco/ConexaoBanco.php";
	
	function convertDataEmDMA($dt)
	{
		$dia = substr($dt,8,2);
		$mes = substr($dt,5,2);
		$ano = substr($dt,0,4);
		$data = $dia."/".$mes."/".$ano;
		return $data;
	}
	$sql = mysql_query("SELECT * FROM funcionario ORDER BY func_data_admissao DESC")or die(mysql_error());
	
	//formatando o pdf
	require("../fpdf/fpdf.php");
	
	$pdf= new FPDF("P","pt","A4");
	
	$pdf->AddPage();
	
	$pdf->Ln(30);
	$pdf->SetFont('Times','B',14);
	$pdf->Cell(0,20,utf8_decode("Relação de Funcionarios que trabalham na Clínica"),0,1,'C');
	$pdf->Cell(0,5,"","B",1,'C');
	$pdf->Ln(50);
	
	//cabeçalho da tabela
	$pdf->SetFont('Times','B',11);
	$pdf->Cell(135,20,'Nome',1,0,"C");
	$pdf->Cell(80,20,'Cargo',1,0,"C");
	$pdf->Cell(85,20,'Telefone',1,0,"C");
	$pdf->Cell(80,20,'CPF',1,0,"C");
	$pdf->Cell(60,20,'Data Nasc.',1,0,"C");
	$pdf->Cell(60,20,utf8_decode('Admissão'),1,0,"C");
	$pdf->Cell(35,20,'Status',1,1,"C");;
	
	 
	//linhas da tabela
	$pdf->SetFont('times','',10);
	while ($ver = mysql_fetch_array($sql)){
	    $pdf->Cell(135,20,utf8_decode($ver['func_nome']),1,0,"L");
	    $pdf->Cell(80,20,utf8_decode($ver['func_cargo']),1,0,"L");
	    $pdf->Cell(85,20,utf8_decode($ver['func_telefone']),1,0,"C");
	    $pdf->Cell(80,20,utf8_decode($ver['func_cpf']),1,0,"C");
	    $pdf->Cell(60,20,convertDataEmDMA($ver['func_data_nasc']),1,0,"C");
	    $pdf->Cell(60,20,convertDataEmDMA($ver['func_data_admissao']),1,0,"C");
	    if ($ver['func_status'] == 1) {
	    	$pdf->Cell(35,20,'Ativo',1,1,"C");
		}
		else{
			$pdf->Cell(35,20,'Inativo',1,1,"C");
		}
	}
	
	$pdf->Output();
	
?>
